package com.site_assembly.apiImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rt.info.api.VisitApi;
import com.rt.info.form.VisitForm;
import com.service.DcsiteApiService;
import com.service.form.DcsiteForm;
import com.site_assembly.common.ValidationUtils;
import com.site_assembly.service.IDcsiteService;
import com.util.Result;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Slf4j
@Api(tags = "区县级站点接口", description = "提供区县级站点相关的 Rest API")
public class DcsiteApiImpl implements DcsiteApiService {

    @Resource
    private IDcsiteService dcsiteService;

    @Resource
    private VisitApi visitApi;

    @Override
    @ApiOperation("根据是否运行（存续/注销）分页查询区域站点")
    public Result findAllDcSiteByPageAndOperatingState(String operatingState, Integer current, Integer pageSize) {

        log.info("站点当前状态{}，当前页{},页容量{}，", operatingState, current, pageSize);
        IPage dcSites = dcsiteService.findAllDcSiteByPageAndOperatingState(operatingState, current, pageSize);

        return Result.success(dcSites);
    }

    @Override
    @ApiOperation("新增区域站点")
    public Result addDcSite(@Valid DcsiteForm dcsiteForm) {

        log.info("区域站点相关资料{}", dcsiteForm);

        ValidationUtils.validate(dcsiteForm);

        Integer num = dcsiteService.addDcSite(dcsiteForm);
        return num > 0 ? Result.success(20000, "新增成功") : Result.fail(40000, "新增失败");
    }

    @Override
    @ApiOperation("修改区域站点状态")
    public Result setDcSiteOfOperatingStateByDcSiteNumber(String dcSiteNumber, String operatingState) {

        log.info("区域站点编号{}，区域站点状态{}", dcSiteNumber, operatingState);

        Integer num = dcsiteService.setDcSiteOfOperatingStateByDcSiteNumber(dcSiteNumber, operatingState);

        return num > 0 ? Result.success(20000, "修改成功") : Result.fail(40000, "修改失败");
    }

    @Override
    public Result getFranchiseInformationByVisitStateAndSiteType(String visitState, String siteType, Integer current, Integer pageSize) {


        return null;
    }

    @Override
    public Result setFranchiseInformationByVisitId(String visitState, String assess, Integer visitId) {


        log.info("加盟信息id{},回复信息{},加盟状态{}", visitState, assess, visitId);
        Result result = visitApi.examineVisit(visitId, assess, visitState);

        return result;
    }
}
